package com.lsege.service.backstage;

import com.lsege.entity.backstage.Indiana;
import com.lsege.entity.backstage.IndianaOrder;
import com.lsege.entity.backstage.Prize;
import com.lsege.mapper.backstage.PrizeMapper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2017/7/8.
 */
@Service
public class PrizeServiceImpl implements PrizeService {
    @Autowired
    PrizeMapper prizeMapper;

//    @Override
//    public Long queryPrizeByName(String prizeName) {
//        return prizeMapper.queryPrizeByName(prizeName);
//    }

//    @Override
//    public Long queryPrizeById(Long id) {
//        return prizeMapper.queryPrizeById(id);
//    }

    @Override
    public void addPrizeInfo(Prize prize) {
        Date date = new Date();
        SimpleDateFormat dt=new SimpleDateFormat("yyMMddhhmmssSSS");
        prize.setPrizeCode("PZ"+dt.format(date));
        prizeMapper.addPrizeInfo(prize);
    }

    @Override
    public List<Prize> queryPrizeList() {
        return prizeMapper.queryPrizeList();
    }

    @Override
    public Long queryPrizeCount() {
        return prizeMapper.queryPrizeCount();
    }

    @Override
    public void deletePrize(String prizeCode) {
        prizeMapper.deletePrize(prizeCode);
    }

    @Override
    public Integer queryPrizeByCode(String prizeCode){
        return prizeMapper.queryPrizeByCode(prizeCode);
    }

    @Override
    public List<Prize> getIndianaList() {
        return prizeMapper.getIndianaList();
    }

    @Override
    public void addIndiana(Indiana indiana){
        indiana.setRemainingTimes(prizeMapper.getPrizePrice(indiana.getPrizeCode()));
        Date date=new Date();
        SimpleDateFormat sd=new SimpleDateFormat("yyMMddhhmmssSSS");
        indiana.setIndianaCode("DB"+sd.format(date));
        prizeMapper.addIndiana(indiana);
        long len=prizeMapper.getPrizePrice(indiana.getPrizeCode());
        int lent=new Long(len).intValue();
        Long[] indnum=new Long[lent];
        for (int i=0;i<len;i++){
            indnum[i]=i+10000001L;
        }
        List list= Arrays.asList(indnum);
        Collections.shuffle(list);
        for (int j=0;j<list.size();j++){
            Long lt=Long.valueOf(list.get(j).toString());
            indiana.setIndianaNumber(lt);
            prizeMapper.addIndianaCode(indiana);
        }

    }

    @Override
    public Long getIndianaCount() {
        return prizeMapper.getIndianaCount();
    }

    @Override
    public List<IndianaOrder> getIndianaOrder() {
        return prizeMapper.getIndianaOrder();
    }

    @Override
    public Long getIndianaOrderCount() {
        return prizeMapper.getIndianaOrderCount();
    }

    @Override
    public void changeExpress(IndianaOrder indianaOrder) {
        prizeMapper.changeExpress(indianaOrder);
    }

    @Override
    public List<IndianaOrder> getIndianaOrderByCode(String orderCode) {
        return prizeMapper.getIndianaOrderByCode(orderCode);
    }

    @Override
    public Long getIndianaOrderByCodeCount(String orderCode) {
        return prizeMapper.getIndianaOrderByCodeCount(orderCode);
    }

    @Override
    public void openPrizeTimes(Indiana indiana) {
        prizeMapper.openPrizeTimes(indiana);
    }
}
